unit AEinterface; { AppleEvent routines and constants that must be called from other units } interface uses Memory, QuickDraw, Packages, Menus, Events, Fonts, Scrap, ToolUtils,Resources, Errors, Palettes, LowMem, AppleEvents,AEObjects, AERegistry, Errors; function AEStatus: Boolean; procedure SendAEScript(processSig:DescType); procedure SendOneAE(inString:str255; inType:DescType; inPtr:Ptr; inSize:LongInt); procedure GetArguments (var str: str255); type AppleEventPtr = ^AppleEvent; var gFrontierAddress : AEAddressDesc; replyPtr : AppleEventPtr; ImagePSN: ProcessSerialNumber; implementation function AEStatus: Boolean; var theError:OSErr; theStatus:Boolean; FrontPSN:ProcessSerialNumber; begin if replyPtr <> nil then begin {AppleEvent in progress } theError := GetFrontProcess(FrontPSN); theError := SameProcess(ImagePSN, FrontPSN, theStatus); AEStatus := theStatus; end else AEStatus := true; end; { *************************************************************************************** This command sends an text string to another program with an AppleEvent. Use to trigger some action by Frontier or to dispatch commands to any program that accepts AppleEvents. The command can have multiple arguments and is similar to Write. *************************************************************************************** } procedure SendAEScript(processSig:DescType); var theAppleEvent:AppleEvent; theError:OSErr; theAEReply:AppleEvent; script: Str255; target:AEDesc; begin GetArguments(script); theError := AECreateDesc(typeApplSignature, @processSig, sizeof(processSig), target); theError := AECreateAppleEvent('misc', 'dosc',target, kAutoGenerateReturnID, kAnyTransactionID, theAppleEvent); theError := AEPutParamPtr(theAppleEvent, keyDirectObject, 'TEXT', Ptr(@script[1]), length(script)); theError := AESend(theAppleEvent, theAEReply, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, nil, nil); theError := AEDisposeDesc(theAppleEvent); theError := AEDisposeDesc(theAEReply); theError := AEDisposeDesc(target); end; function MakeDescFromString(inString:str255):DescType; var answer:DescType; i:integer; begin answer := ' '; if inString = 'Igor' then answer := 'IGRO' else if inString = 'Igor Pro' then answer := 'IGRO' else if inString = 'advance' then answer := 'VAST' else begin for i := 1 to Length(instring) do if i < 5 then answer[i] := inString[i]; end; MakeDescFromString := answer; end; { *************************************************************************************** This command sends an AppleEvent to any program. *************************************************************************************** } procedure SendOneAE(inString:str255; inType:DescType; inPtr:Ptr; inSize:LongInt); var theAppleEvent:AppleEvent; theError:OSErr; theAEReply:AppleEvent; script: Str255; target:AEDesc; name:str255; progname:str255; processSig,event,suite:DescType; i:integer; begin if Length(inString) < 12 then exit(SendOneAE); processSig := ' '; event := ' '; suite := ' '; for i := 1 to 4 do processSig[i] := inString[i]; for i := 5 to 8 do suite[i-4] := inString[i]; for i := 9 to 12 do suite[i-8] := inString[i]; theError := AECreateDesc(typeApplSignature, @processSig, sizeof(processSig), target); theError := AECreateAppleEvent(suite, event,target, kAutoGenerateReturnID, kAnyTransactionID, theAppleEvent); theError := AEPutParamPtr(theAppleEvent, keyDirectObject, inType, inPtr, inSize); theError := AESend(theAppleEvent, theAEReply, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, nil, nil); theError := AEDisposeDesc(theAppleEvent); theError := AEDisposeDesc(theAEReply); theError := AEDisposeDesc(target); end; end.